package com.qf.business.course.controller;

import com.qf.business.course.service.CourseGuigeService;
import com.qf.business.course.service.CourseGuigeValService;
import com.qf.commons.data.result.R;
import com.qf.data.course.entity.CourseGuige;
import com.qf.data.course.entity.CourseGuigeVal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * author Ken
 * create_time 2022/9/22
 */
@RestController
@RequestMapping("/course/guige")
public class CourseGuigeController {

    @Autowired
    private CourseGuigeService courseGuigeService;

    @Autowired
    private CourseGuigeValService courseGuigeValService;

    /**
     * 规格列表
     * @return
     */
    @RequestMapping("/list")
    public R list(){
        List<CourseGuige> courseGuiges = courseGuigeService.list();
        return R.create(courseGuiges);
    }

    /**
     * 根据规格id 查询当前规格下的所有可选值
     * @param gid
     * @return
     */
    @RequestMapping("/vals")
    public R guigeVals(Integer gid){
        List<CourseGuigeVal> vals = courseGuigeValService
                .query()
                .eq("gid", gid)
                .list();

        return R.create(vals);
    }

    /**
     * 新增规格
     * @param courseGuige
     * @return
     */
    @RequestMapping("/insert")
    public R insert(CourseGuige courseGuige){
        courseGuigeService.save(courseGuige);
        return R.create(null);
    }

    /**
     * 新增规格的可选值
     * @param guigeVal
     * @return
     */
    @RequestMapping("/insertVal")
    public R guigeValInsert(CourseGuigeVal guigeVal){
        courseGuigeValService.save(guigeVal);
        return R.create(guigeVal);
    }
}
